package cn.zs.supply.common.core.domain.result;

import cn.zs.supply.common.core.domain.vo.BaseVo;
import cn.zs.supply.common.core.exception.BusiException;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.ToString;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@Data
@ToString(callSuper = true)
public class WaterFallPageResult<T extends BaseVo> extends BaseResult {
    @JsonProperty("data")
    private Collection<T> result;      //数据列表。
    private Long nextOffset;   //下一页的起始值。
    private Date nextTime;  //请求时间.

    public Collection<T> getResult(boolean isThrowException) {
        if (isThrowException) {
            if (getSuccess() != null && !getSuccess()) {
                throw new BusiException(getErrcode(), getErrmsg());
            } else if (result == null) {
                result = new ArrayList<>();
            }
        }
        return result;
    }
}
